package com.android.test.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class InternetManager {
	public static boolean hasInternet(Context context) {
		ConnectivityManager manager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = manager.getActiveNetworkInfo();
		if (info == null || !info.isConnected()) {
			return false;
		}
//		if (info.isRoaming()) {
//			//漫游
//			return true;
//		}
		return true;
	}
	
	public static boolean isWiFiActive(Context inContext) {  
        Context context = inContext.getApplicationContext();  
        ConnectivityManager connectivity = (ConnectivityManager) context  
                .getSystemService(Context.CONNECTIVITY_SERVICE);  
        if (connectivity != null) {  
            NetworkInfo[] info = connectivity.getAllNetworkInfo();  
            if (info != null) {  
                for (int i = 0; i < info.length; i++) {  
                    if (info[i].getTypeName().equals("WIFI") && info[i].isConnected()) {  
                        return true;  
                    }  
                }  
            }  
        }  
        return false;  
    }  
	public static boolean hasMoreThanOneConnection(Context context){
		ConnectivityManager manager = (ConnectivityManager)context
			.getSystemService(Context.CONNECTIVITY_SERVICE);
		if(manager==null){
			return false;
		}else{
			NetworkInfo [] info = manager.getAllNetworkInfo();
			int counter = 0;
			for(int i = 0 ;i<info.length;i++){
				if(info[i].isConnected()){
					counter++;
				}
			}
			if(counter>1){
				return true;
			}
		}
		
		return false;
	}
}
